package com.wellgoon.test.jse81;

public class Candidate {
    String name;
    int age;

    public Candidate(String name, int age) throws Exception {
        if (name == null) {
            throw new MissingException();
        } else if (age <= 10 || age > 150) {
            throw new AgeOutOfException();
        } else {
            this.name = name;
            this.age = age;
        }
    }

    @Override
    public String toString() {
        return name + " age=" + age;
    }

    public static void main(String[] args) {
        Candidate c1 = null;
        Candidate c2 = null;
        try {
            c1 = new Candidate("James", 20);
            c2 = new Candidate("Williams", 20);
        }catch (MissingException missingException){

        }catch (AgeOutOfException ageOutOfException){

        }catch (Exception e) {
            throw new RuntimeException(e);
        }
        System.out.println(c1);
        System.out.println(c2);
    }
}

class MissingException extends Exception {
}

class AgeOutOfException extends Exception {
}
